// Renamed your  _handleBankingChoice to _performTransaction

this._pendingTransaction = null; // "deposit" or "withdrawal" - anything else is to be ignored

this._showBankingScreen = function (caller) {
    // If the _pendingTransaction flag is set, we have to:

    // TODO: if this._pendingTransaction is set,
    // 1. catch any values of caller that look like numbers

    // TODO: if caller was a positive integer, use it as the amount parameter to call this._pendingTransaction() 
    // 2. Process the transaction, either deposit or withdrawal
          this._performTransaction(this._pendingTransaction, amount)

    // If caller has an unexpected value, just ignore, it will cause the default starting screen to be displayed.
    // 3. Reset _pendingTransaction to null
    this._pendingTransaction = null;

    // 4. Continue on to the default starting screen message, which
    //    will be composed using the updated balances.
     
    // Parameters for the starting screen

    var message = "Welcome to Witch Bank. Your current balance: " +
                  missionVariables.WitchBank_cashAtBank + " credits in bank, " +
                  missionVariables.WitchBank_cashInWallet + " credits in wallet.";

    var optionsMenu = {
        "1_DEPOSIT" = "Make a DEPOSIT",
        "2_WITHDRAWAL" = "Make a WITHDRAWAL",
        "3_blank" = "",
        "4_EXIT" = "EXIT secure banking"
    };
    var parameters = {
        screenID: "BANKING_SCREEN",
        allowInterrupt: true,
        exitScreen: "GUI_SCREEN_INTERFACES",
        background: { name: "witchbank_background.png", height: 480 },
        title: "Witch Bank",
        message: message,
        choices: optionsMenu
    };
    // Adjust parameters for displayed text, if not the starting screen
    switch (caller) {
         case "deposit":
            this._pendingTransaction = "deposit";
            parameters.titleKey  = "banking_deposit_title";
            parameters.messageKey = "banking_deposit_message";
            parameters.textEntry = true; // replaces "choices" with text entry field.
            break;

        case "withdrawal":
            this._pendingTransaction = "withdrawal";
            parameters.titleKey   = "banking_withdrawal_title";
            parameters.messageKey = "banking_withdrawal_message";
            parameters.textEntry = true; // replaces "choices" with text entry field.
            break;

        default:
            // No changes to starting screen
            break;
    }

    mission.runScreen(parameters, callback);

        function callback(choice) {
            if (choice !== "4_EXIT") {
                if (choice === "1_DEPOSIT") {
                    this._showBankingScreen("deposit");
                } else if (choice === "2_WITHDRAWAL") {
                    this._showBankingScreen("withdrawal");
                } else {
                    player.ship.dockedStation.setInterface("witch_bank", {
                    title: "Witch Bank",
                    category: expandDescription("[interfaces-category-organisations]"),
                    summary: "Witch Bank is the trusted name in interstellar banking. Current balance: " + missionVariables.WitchBank_cashAtBank + " credits.",
                    callback: this._showBankingScreen.bind(this)
                    });
                    this._showBankingScreen("witch_bank");
                }
          }
    
    }
};



this._performTransaction = function (transType, amount) {
    switch (transType) {
        case "deposit":
            // Transfer credits from wallet to bank
            if (amount > 0 && amount <= missionVariables.WitchBank_cashInWallet) {
                missionVariables.WitchBank_cashAtBank += amount;
                missionVariables.WitchBank_cashInWallet -= amount;
                player.consoleMessage("Deposited " + amount + " credits.", 6);
                log(this.name, "Deposited " + amount + " credits. New balances: Bank=" +
                    missionVariables.WitchBank_cashAtBank + ", Wallet=" +
                    missionVariables.WitchBank_cashInWallet);
            } else {
                player.consoleMessage("Invalid deposit amount.", 6);
            }
            break;

        case "withdraw":
            // Transfer credits from bank to wallet
            if (amount > 0 && amount <= missionVariables.WitchBank_cashAtBank) {
                missionVariables.WitchBank_cashAtBank -= amount;
                missionVariables.WitchBank_cashInWallet += amount;
                player.consoleMessage("Withdrew " + amount + " credits.", 6);
                log(this.name, "Withdrew " + amount + " credits. New balances: Bank=" +
                    missionVariables.WitchBank_cashAtBank + ", Wallet=" +
                    missionVariables.WitchBank_cashInWallet);
            } else {
                player.consoleMessage("Invalid withdrawal amount.", 6);
            }
            break;

        default:
            // Exit screen or invalid choice
            player.consoleMessage("Invalid banking operation.", 6);
            break;
    }
};